/* 

Project: 		The Impact of Short-Term Employment for Low-Income Youth: Experimental 	
				Evidence from the Philippines
Authors: 		Emily A. Beam and Stella Quimbo

***********************************
Path: 			code/02_analysis
File name: 		table_a12.do 
***********************************

Purpose: 		Generates Table A12 on how payments were spent

Inputs: 		spes_data.dta
Outputs: 		log file for Appendix Table A12 (manually generated)

Log: 			results/03_output/log_table_a12.log		

Last updated: 	16 November 2021

*/

cap log close 

log using "$output/log_table_a12.log",replace

use "$usedata_analysis/spes_data", clear
	keep if endline == 1

tab spes_payment_spent

/*
spent	1	Helped support family
spent	2	Saved for the future
spent	3	Paid tuition fee/schooling expenses
spent	4	Bought personal effects
spent	5	Paid for extra-curricular activities
spent	-222	Other, specify
spent	-98	Refused

*/ 

loc l1 "Helped support family"
loc l2 "Saved for the future"
loc l3 "Paid tuition fee/schooling expenses"
loc l4 "Bought personal effects"
loc l5 "Paid for extra-curricular activities"

// Clean the others 

replace spes_payment_spent = "" if spes_payment_spent == "-98"

gen _spes_payment_spent6 = regexm(spes_payment_spent,"-222")
	replace _spes_payment_spent6 = . if spes_payment_spent == ""

replace spes_payment_spent = trim(subinstr(spes_payment_spent,"-222","",.))

gen _spes_payment_spent_comment = spes_payment_spent_other
	replace _spes_payment_spent_comment = "" if regex(spes_payment_spent_other,"not yet") | regex(		_spes_payment_spent_comment,"receive")
	replace _spes_payment_spent6 = 0 if regex(spes_payment_spent_other,"not yet") | regex(			_spes_payment_spent_comment,"receive")



forval i = 1/5{ 
	
	gen _spes_payment_spent`i' = . 
		replace _spes_payment_spent`i' = 0 if !missing(spes_payment_spent) | !missing(	_spes_payment_spent6)
		replace _spes_payment_spent`i' = 1 if regexm(spes_payment_spent,"`i'")
	label var _spes_payment_spent`i' "`l`i''"
		
}

sum _spes_payment_spent1-_spes_payment_spent5 _spes_payment_spent6

label var _spes_payment_spent6 "Other"



** Data cleaning 

// Education
replace _spes_payment_spent3 = 1 if regex(_spes_payment_spent_comment,"educ") | regex(_spes_payment_spent_comment,"sch")| regex(_spes_payment_spent_comment,"fees")
replace _spes_payment_spent6 = 0 if regex(_spes_payment_spent_comment,"educ") | regex(_spes_payment_spent_comment,"sch")| regex(_spes_payment_spent_comment,"fees")
replace _spes_payment_spent_comment = "" if regex(_spes_payment_spent_comment,"educ") | regex(_spes_payment_spent_comment,"sch")| regex(_spes_payment_spent_comment,"fees")

// Saving
replace _spes_payment_spent2 = 1 if regex(_spes_payment_spent_comment,"save") | regex(_spes_payment_spent_comment,"deposit")
replace _spes_payment_spent6 = 0 if regex(_spes_payment_spent_comment,"save") | regex(_spes_payment_spent_comment,"deposit")
replace _spes_payment_spent_comment = "" if regex(_spes_payment_spent_comment,"save") | regex(_spes_payment_spent_comment,"deposit")
// Family
replace _spes_payment_spent1 = 1 if regex(_spes_payment_spent_comment,"kapatid")
replace _spes_payment_spent6 = 0 if regex(_spes_payment_spent_comment,"kapatid") 
replace _spes_payment_spent_comment = "" if regex(_spes_payment_spent_comment,"kapatid") 

// Personal
replace _spes_payment_spent4 = 1 if regex(_spes_payment_spent_comment,"birthday") | regex(_spes_payment_spent_comment,"cell") |  regex(_spes_payment_spent_comment,"personal") |  regex(_spes_payment_spent_comment,"allowance") 
replace _spes_payment_spent6 = 0 if regex(_spes_payment_spent_comment,"birthday") | regex(_spes_payment_spent_comment,"cell") |  regex(_spes_payment_spent_comment,"personal") |  regex(_spes_payment_spent_comment,"allowance") 
replace _spes_payment_spent_comment = "" if regex(_spes_payment_spent_comment,"birthday") | regex(_spes_payment_spent_comment,"cell") |  regex(_spes_payment_spent_comment,"personal") |  regex(_spes_payment_spent_comment,"allowance") 

sum _spes_payment_spent1-_spes_payment_spent5 _spes_payment_spent6

estpost tabstat _spes_payment_spent3 _spes_payment_spent1 _spes_payment_spent4 _spes_payment_spent5  _spes_payment_spent2 _spes_payment_spent6,  statistics(sum mean  n) columns(statistics ) listwise  elabels

** Create payment table 
mrtab _spes_payment_spent1-_spes_payment_spent5 _spes_payment_spent6,sort desce


log close 
